<?php

namespace Home\Controller;
use Think\Controller;

class NewsController extends Controller{
    public function index(){
        $this->display();
    }
    
    function news_list() {
        $news = D("news");
        $total = $news->count();
        $pageSize = $_GET['pageSize'];
        if ($pageSize == '' || !is_numeric($pageSize) || $pageSize <= 0) {
            $pageSize = 10;
        }
        $page = new \Component\Page($total, $pageSize);
        $sql = "select * from dy_news order by add_time desc " . $page->limit;
        
        $info = $news->query($sql);
        $pageInfo = $page->fpage();
        $this->assign('pageInfo', $pageInfo);
        $this->assign("news", $info);
        
        $this->display();
    }
    
    function add_news() {
        $add_time = date("Y-m-d H:i:s");
        $this->assign("add_time", $add_time);
        $this->display();
    }
    
    function add_news_act() {
        $news['title'] = I('post.title');
        $news['key_words'] = I('post.key_words');
        $news['add_time'] = I('post.add_time');
        //取消转义
        $news['content'] = stripslashes(htmlspecialchars_decode(I('post.editorValue')));
        //$news['content'] = I('post.editorValue');
        $NewsModel = new \Common\Model\NewsModel();
        $NewsModel->add($news);
        
//        $this->display();
    }
    
    function news_detail(){
        $id = I('get.id');
        $NewsModel = new \Common\Model\NewsModel();
        $news = $NewsModel->find($id);
        $this->assign("news", $news);
        $this->display();
    }
}
